package com.evil.kingdom.pojo.entity.core;

import cn.hutool.core.bean.BeanUtil;
import com.evil.kingdom.pojo.dto.core.ItemDto;
import com.evil.kingdom.pojo.entity.base.Fight;
import com.evil.common.mongo.entity.SingleName;
import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Objects;

/**
 * 物品
 *
 * @author liyang
 * @date 2024-05-17 16:20
 */
@Getter
@Setter
@Document
@NoArgsConstructor
public class Item extends Fight implements SingleName {

    /**
     * 名称
     */
    @Id
    @NotBlank(message = "名称不能为空")
    private String name;

    public Item(ItemDto dto) {
        BeanUtil.copyProperties(dto, this);
    }

    @Override
    public String getEntityName() {
        return "物品";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Item item = (Item) o;

        return Objects.equals(name, item.name);
    }

    @Override
    public int hashCode() {
        return name != null ? name.hashCode() : 0;
    }

    @Override
    public String toString() {
        return name;
    }
}
